﻿using System.Windows;
using System.Windows.Threading;
using Connector;
using System.Diagnostics;
using DBSearch.Properties;

namespace DBSearch
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        public App()
        {
            DispatcherUnhandledException += new DispatcherUnhandledExceptionEventHandler(App_DispatcherUnhandledException);
            Logger.FileName = Settings.Default.LogfilePath;
            Logger.TraceLevel = Settings.Default.LogLevel;
        }

        /// <summary>
        /// Logg all unhandled exceptions of the Application.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
        {
            string message = Logger.CreateExceptionMessage(e.Exception);
            Logger.LogError(message);
            MessageBox.Show("The following error occoures:\n" + message, "Error!");
            e.Handled = true;
        }
    }
}
